package com.purchase.manage.controller;

import com.alibaba.fastjson2.JSON;
import com.purchase.common.annotation.Log;
import com.purchase.common.core.controller.BaseController;
import com.purchase.common.core.domain.AjaxResult;
import com.purchase.common.enums.BusinessType;
import com.purchase.manage.damian.Purchase;
import com.purchase.manage.service.IManagePurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @author oyi46
 * @version 1.0
 * Create by 2023/7/3 14:34
 */

@RestController
@RequestMapping("/purchase")
public class PurchaseController extends BaseController {

    @Autowired
    IManagePurchaseService managePurchaseService;

    @PreAuthorize("@ss.hasPermi('manage:manage:manage')")
    @Log(title = "采购员添加", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult addPurchase(@RequestBody Purchase purchase) {
        if (!managePurchaseService.checkUser(purchase)) {
            return error("新增采购员'" + purchase.getName() + "'失败，该账号已存在");
        }
        if (managePurchaseService.addPurchase(purchase) != 1) {
            return error("新增采购员'" + purchase.getName() + "'注册失败");
        }
        return success();
    }

    @PreAuthorize("@ss.hasPermi('manage:manage:manage')")
    @Log(title = "采购员修改个人信息", businessType = BusinessType.INSERT)
    @PutMapping
    public AjaxResult updatePurchase(@RequestBody Purchase purchase) {
        managePurchaseService.updatePurchase(purchase);
        return success();
    }
}
